<template>
  <div>
    <el-form
      :model="form"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="save()"
      label-width="80px"
      size="mini"
    >
      <h3>基本信息</h3>
      <el-form-item label="企业名称" prop="name">
        <el-col :span="8">
          <el-input v-model="form.name"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="成立日期" prop="establishDate">
        <el-col :span="8">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.establishDate"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="营业执照编码" prop="businessCode">
        <el-col :span="8">
          <el-input v-model="form.businessCode"></el-input>
        </el-col>
      </el-form-item>
      <h3>管理员信息</h3>
      <el-form-item label="管理员账号" prop="adminAccount">
        <el-col :span="8">
          <el-input v-model="form.adminAccount"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="管理员密码" prop="adminPassword">
        <el-col :span="8">
          <el-input v-model="form.adminPassword"></el-input>
        </el-col>
      </el-form-item>
      <h3>bucket初始信息</h3>
      <el-form-item label="bucket名" prop="bucketName">
        <el-col :span="8">
          <el-input v-model="form.bucketName"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="endpoint" prop="endpoint">
        <el-col :span="8">
          <el-input v-model="form.endpoint"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="accessKeyId" prop="accessKeyId">
        <el-col :span="8">
          <el-input v-model="form.accessKeyId"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="accessKeySecret" prop="accessKeySecret">
        <el-col :span="8">
          <el-input v-model="form.accessKeySecret"></el-input>
        </el-col>
      </el-form-item>
      <el-button type="primary" @click="save()">确定</el-button>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save()">确定</el-button>
      </span>
    </el-form>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {},
      dataRule: {
        name: { required: true, message: '企业名不能为空', trigger: 'blur' },
        establishDate: {
          required: true,
          message: '成立日期不能为空',
          trigger: 'blur'
        },
        businessCode: {
          required: true,
          message: '营业执照编码不能为空',
          trigger: 'blur'
        },
        bucketName: {
          required: true,
          message: 'bucket名不可为空',
          trigger: 'blur'
        },
        endpoint: {
          required: true,
          message: 'endpoint不能为空',
          trigger: 'blur'
        },
        accessKeyId: {
          required: true,
          message: 'accessKeyId不能为空',
          trigger: 'blur'
        },
        accessKeySecret: {
          required: true,
          message: 'accessKeySecret不能为空',
          trigger: 'blur'
        },
        adminAccount: {
          required: true,
          message: '管理员账号不能为空',
          trigger: 'blur'
        },
        adminPassword: {
          required: true,
          message: '管理员密码不能为空',
          trigger: 'blur'
        }
      }
    }
  },
  methods: {
    save () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/sys/ent/save`),
            method: 'post',
            data: this.$http.adornData(
              //   {
              //     name: this.form.name || undefined,
              //     establishDate: this.form.establishDate,
              //     businessCode: this.form.businessCode,
              //     bucketName: this.form.bucketName,
              //     endpoint: this.form.endpoint,
              //     acessKeyId: this.form.acessKeyId,
              //     acessKeySecret: this.form.acessKeySecret
              //   }
              this.form
            )
          }).then(({ data }) => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$router.replace({ name: 'sys-ent' })
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>

<style>
</style>